/* -----------------------------------------------------------------------
 * Demonstration of how to write unit tests for dominion-base
 * Include the following lines in your makefile:
 *
 * testUpdateCoins: testUpdateCoins.c dominion.o rngs.o
 *      gcc -o testUpdateCoins -g  testUpdateCoins.c dominion.o rngs.o $(CFLAGS)
 * -----------------------------------------------------------------------
 */

#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "rngs.h"

// set NOISY_TEST to 0 to remove printfs from output
#define NOISY_TEST 1

int main() {
  int i;
  int seed = 1000;
  int numPlayer = 2;
  int maxBonus = 10;
  int p, r, handCount;
  int bonus;
  int k[10] = {adventurer, council_room, feast, gardens, mine
               , remodel, smithy, village, baron, great_hall};

  //test that two cards are the not same
  int kx1[10] = {adventurer, council_room, feast, gardens, mine
               , remodel, smithy, village, baron, mine};

  //test that there are a wrong number of k cards
  int kx2[9] = {adventurer, council_room, feast, gardens, mine
               , remodel, smithy, village, baron};
  struct gameState G;
  int maxHandCount = 5;
  // arrays of all coppers, silvers, and golds
  int coppers[MAX_HAND];
  int silvers[MAX_HAND];
  int golds[MAX_HAND];
   
#if (NOISY_TEST == 1)
  printf("\n\nTest Initalize Game\n");
  printf("Test valid number players");
#endif
  for (numPlayer = 0; numPlayer < 6; numPlayer ++)
    {
      memset(&G, 23, sizeof(struct gameState));   // clear the game state
      r = initializeGame(numPlayer, k, seed, &G); // initialize a new game
      if (numPlayer <= 1){
#if (NOISY_TEST == 1)
	printf("Number of players is equal to one or zero.  Function did not continue. OK\n");
#endif
	assert(r == -1);
      }
      if (numPlayer > 4){
	
#if (NOISY_TEST == 1)
	printf("Number of players is equal to more than 4.  Function did not continue.  OK\n");
#endif
	assert(r == -1);
      }

#if (NOISY_TEST == 1)
      printf("Testing same cards in deck\n\n");
#endif
      memset(&G, 23, sizeof(struct gameState));   // clear the game state
      r = initializeGame(2, kx1, seed, &G); // initialize a new game
      assert(r == -1);
      printf("Same kingdom card seen");

#if (NOISY_TEST == 1)
      printf("Testing 9 kingdom cards");
#endif
      memset(&G, 23, sizeof(struct gameState));   // clear the game state
      r = initializeGame(numPlayer, kx2, seed, &G); // initialize a new game
      assert(r == -1);     

    }


  printf("All tests passed!\n");
  printf("Incorrect number of players failed, correct number of players passed. \n \n");
  printf("Correct number of king cards passed, same number of k cards failed, incorrect deck failed.  Test Passed\n");
  return 0;
}
